package Server.Dwc.azxy5;

import java.util.Random;


//28��
public class GameLogic {

	final int m_cbCardListData[] = { 
			//1-9Ͳ     4���װ�
			0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
			0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
			0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
			0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
			
	};

	public int CountArray(int by[]) {
		return by.length;
	}

	public int sizeof(int by[]) {
		return by.length;
	}

	public void CopyMemory(int[] by, int[] by2, int length) {
		for (int i = 0; i < length; i++) {
			by[i] = by2[i];
		}
	}

	public Random rd = new Random();

	public int rand() {
		return rd.nextInt(1000);
	}

	// �����˿�
	void RandCardList(int cbCardBuffer[], int cbBufferCount) {
		// ����׼��
		int cbCardData[] = new int[CountArray(m_cbCardListData)];
		CopyMemory(cbCardData, m_cbCardListData, sizeof(m_cbCardListData));

		// �����˿�
		int cbRandCount = 0;
		int cbPosition = 0;
		do {
			cbPosition = rand() % (CountArray(cbCardData) - cbRandCount);
			cbCardBuffer[cbRandCount++] = cbCardData[cbPosition];
			cbCardData[cbPosition] = cbCardData[CountArray(cbCardData) - cbRandCount];
		} while (cbRandCount < cbBufferCount);

		return;
	}

	void RandCardListEx(int cbCardBuffer[], int cbBufferCount) {
		int cbCardData[] = new int[cbBufferCount];
		CopyMemory(cbCardData, cbCardBuffer, cbBufferCount);

		// �����˿�
		int cbRandCount = 0;
		int cbPosition = 0;
		do {
			cbPosition = rand() % (cbBufferCount - cbRandCount);
			cbCardBuffer[cbRandCount++] = cbCardData[cbPosition];
			cbCardData[cbPosition] = cbCardData[cbBufferCount - cbRandCount];
		} while (cbRandCount < cbBufferCount);
	}

	//1-9�� ��һ��28��
	final int CT_SPECIAL_0 = 0;
	final int CT_SPECIAL_1 = 1;
	final int CT_SPECIAL_2 = 2;
	final int CT_SPECIAL_3 = 3;
	final int CT_SPECIAL_4 = 4;
	final int CT_SPECIAL_5 = 5;
	final int CT_SPECIAL_6 = 6;
	final int CT_SPECIAL_7 = 7;
	final int CT_SPECIAL_8 = 8;
	final int CT_SPECIAL_9 = 9;
	final int CT_SPECIAL_28 = 10;
	
	//����
	final int CT_SPECIAL_11 = 11;
	final int CT_SPECIAL_22 = 12;
	final int CT_SPECIAL_33 = 13;
	final int CT_SPECIAL_44 = 14;
	final int CT_SPECIAL_55 = 15;
	final int CT_SPECIAL_66 = 16;
	final int CT_SPECIAL_77 = 17;
	final int CT_SPECIAL_88 = 18;
	final int CT_SPECIAL_99 = 19;
	final int CT_SPECIAL_1010 = 20;
	final int CT_POINT = 0;

	int RetType(int itype) {
		itype = itype % 10;
		switch (itype) {
		case 0:
			return CT_SPECIAL_0;
		case 1:
			return CT_SPECIAL_1;
		case 2:
			return CT_SPECIAL_2;
		case 3:
			return CT_SPECIAL_3;
		case 4:
			return CT_SPECIAL_4;
		case 5:
			return CT_SPECIAL_5;
		case 6:
			return CT_SPECIAL_6;
		case 7:
			return CT_SPECIAL_7;
		case 8:
			return CT_SPECIAL_8;
		case 9:
			return CT_SPECIAL_9;
		default:
			return CT_POINT;
		}
	}

	public int CT_ERROR_CARD = 0;
	public int NIUNIU_CARD_COUNT = 40;
	public int ST_VALUE = 1; // ��ֵ����
	public int ST_NEW = 3; // ��ֵ����
	public int ST_LOGIC = 2; // �߼�����
	
	// ��ȡ����
	int GetCardType(int cbCardData[], int cbCardCount) {
		return 0;
	}

	int GetCardType(int cbCardData[], int cbCardCount, int[] bcOutCadData) {
		return 0;
	}

	int CompareCard(int cbFirstCardData[], int cbFirstCardCount, int cbNextCardData[], int cbNextCardCount) {
		return 0;
	}


	int LOGIC_MASK_VALUE = 0x0F;
	
	int GetCardValue(int cbCardData) {
		return (int) (cbCardData & LOGIC_MASK_VALUE);
	}


	int GetCardNewValue(int cbCardData) {
		int cbCardValue = GetCardValue(cbCardData);

		return cbCardValue;
	}

	int GetCardLogicValue(int cbCardData) {
		int cbValue = GetCardValue(cbCardData);
		if (cbValue > 10) {
			cbValue = 10;
		}
		return cbValue;
	}
}
